package com.atguigu.xml;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

public class ZqkCreateXml {
    public static void main(String[] args) throws Exception {

    Document document = DocumentHelper.createDocument();
        Element studentElement = document.addElement("student");
        document.setRootElement(studentElement);

        Element nameElement = studentElement.addElement("name");
        Element sexElement = studentElement.addElement("sex");
        Element ageElement = studentElement.addElement("age");

        nameElement.addText("张三");
        sexElement.addText("男");
        ageElement.addText("23");

        OutputFormat format = new OutputFormat("    ", true);
        OutputStream os = new FileOutputStream("student.xml");
        XMLWriter xmlWriter = new XMLWriter(os, format);
        xmlWriter.write(document);




    }

}
